import 'package:boss/models/cloud_printer.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/widget/button/radius_button.dart';
import 'package:boss/ui/widget/modal/modal.dart';
import 'package:boss/ui/widget/title_number_field.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

Future<List<PrinterPlanBillList>> pickerBillStyleModal(BuildContext context, List<PrinterPlanBillList> data) {
  return showModal(
    context,
    builder: (context) => _PickerBillStyle(
      data: data,
    ),
  );
}

class _PickerBillStyle extends StatefulWidget {
  final List<PrinterPlanBillList> data;

  const _PickerBillStyle({this.data});

  @override
  __PickerBillStyleState createState() => __PickerBillStyleState();
}

class __PickerBillStyleState extends State<_PickerBillStyle> {
  List<PrinterPlanBillList> data = [];

  @override
  void initState() {
    super.initState();

    data = widget.data.map((item) => PrinterPlanBillList.fromJson(item.toJson())).toList();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 660.w,
      height: 620.w,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(
          10.w,
        ),
      ),
      padding: EdgeInsets.all(
        30.w,
      ),
      child: Column(
        children: <Widget>[
          Container(
            child: Text(
              '打印票据',
              style: TextStyleConstant().normal_1_32,
            ),
          ),
          Expanded(
            child: ListView.builder(
              padding: EdgeInsets.all(0),
              itemBuilder: (context, index) {
                var current = data[index];

                return TitleNumberField(
                  title: current.billName,
                  value: current.count,
                  onChanged: (value) {
                    current.count = value;
                  },
                );
              },
              itemCount: data.length,
            ),
          ),
          RadiusButton(
            width: double.infinity,
            title: '确定',
            onTap: () {
              Navigator.pop(context, data);
            },
          ),
        ],
      ),
    );
  }
}
